<template>
	<view class="withdraw-history">
		<view class="search-box u-flex">
			<view class="sctionContent">
				<image style="width: 24px;height: 24px;" src="@/static/my/rili.png" mode=""></image>
				<u-input v-model="startDate" type="text" disabled input-align="center" placeholder="开始日期" @click="show = true" />
				<text>至</text>
				<u-input v-model="endDate" type="text" disabled input-align="center" placeholder="结束日期" @click="show = true" />
			</view>
			<u-button style="margin-right: 30rpx" type="primary" color="#147BDB" @click="onSearch"><u-icon name="search" style="margin-right: 10rpx;"></u-icon>搜索</u-button>
		</view>
		<view class="list">
			<view class="list-item"v-for="(item, index) in tableData" :key="index">
				<view class="l-i-name">
					用户名：{{item.userName}}
				</view>
				<view >
					<u-tag :text="'划转数量' + item.sweet" color="#FFA800" border-color="#FFA800" bg-color="#FFFFFF" size="mini" mode="plain" />
				</view>
				<view class="l-i-desc">
					划转类型：{{typeText[item.transferType]}}
				</view>
				<view class="l-i-time">
					{{item.createDate}}
				</view>
			</view>
		</view>
		<u-empty v-show="tableData.length <= 0" style="margin-top:100rpx" text="暂时没有数据" mode="list"></u-empty>
		<u-loadmore v-show="tableData.length > 0" :status="status" />
		<u-calendar v-model="show" mode="range" @change="timeOnchange"></u-calendar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				show: false,
				page: 1,
				size: 10,
				startDate: '',
				endDate: '',
				total: 0,
				tableData: [],
				typeText: {
					1: '商户账户划转至个人账户',
					2: '个人账户划转至商户账户'
				}
			}
		},
		
		onLoad() {
			this.getData()
		},
		methods: {
			onReachBottom() {
				if(this.tableData.length >= this.total) return ;
				this.status = 'loading';
				this.page = ++ this.page;
				setTimeout(() => {
					this.getData()
					if(this.tableData.length >= this.total) this.status = 'nomore';
					else this.status = 'loading';
				}, 2000)
			},
			onSearch() {
				this.page = 1;
				this.total = 0;
				this.tableData = [];
				this.getData()
			},
			timeOnchange(e) {
				this.startDate = e.startDate;
				this.endDate = e.endDate;
				
			},
			getData() {
				this.$u.api.getTransItems({
					// check_status: this.formInline.check_status,
					mid: uni.getStorageSync('mid'),
					page: this.page,
					size: this.size,
					start_date: this.startDate,
					end_date: this.endDate
				}).then(res => {
					if(res.code == 0) {
						if (res.data.length > 0) {
							this.tableData = [...this.tableData, ...res.data];
						} else {
							// 分页结束
							this.status = 'nomore';
						}
						if (this.tableData.length  >= this.total) {
							this.status = 'nomore';
						}
						this.total = res.extraInfo;
					} else {
						uni.showToast({
							icon:'none',
						    title: res.msg
						});
					}
				})
			}
		}
	}
</script>

<style scoped>
	.search-box {
		padding-top: 33rpx;
	}
	.sctionContent {
		display: flex;
		align-items: center;
		justify-content: space-around;
		border: 1rpx solid #D2D1D1;
		padding: 6rpx;
		margin: 0 20rpx 0 30rpx;
		border-radius: 8rpx;
	}
	.list {
		padding: 0 30rpx;
	}
	.list-item {
		position: relative;
		margin-top: 24rpx;
		margin-bottom: 24rpx;
		padding: 20rpx 33rpx;
		height: 248rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		box-shadow: 0rpx 0rpx 18rpx 0rpx rgba(189, 189, 190, 0.6);
		border-radius: 10rpx;
		font-size: 24rpx;
		color: #666666;
	}
	.l-i-name {
		color: #333333;
		font-size: 30rpx;
	}
	.l-i-tag {
		color: #FFCD5F;
		border: 1rpx solid #FFCD5F;
	}
	
</style>
